﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data.Common;

namespace RFIDStockManagement.DAL
{
    public static class DALHelper
    {
        private static DbHelper _db;
        static DALHelper()
        {
            _db =new DbHelper();
        }

        /// <summary>
        /// 用于取单据ID
        /// </summary>
        /// <param name="tableName">当前存储ID的表名</param>
        /// <param name="increment">步长</param>
        /// <returns></returns>
        public static long GetBillID(string tableName,int increment)
        {
            DbCommand cmd = _db.GetStoredProcCommand("GetICMaxNum");
            SqlParameter newParm = new SqlParameter("@TableName", System.Data.SqlDbType.NVarChar);
            newParm.Size = 100;
            newParm.Value = tableName;
            cmd.Parameters.Add(newParm);

            newParm = new SqlParameter("@Increment",System.Data.SqlDbType.Int);
            newParm.Value = increment;
            cmd.Parameters.Add(newParm);

            newParm = new SqlParameter("@FInterID", System.Data.SqlDbType.Int);
            newParm.Value = -1;
            newParm.Direction = System.Data.ParameterDirection.Output;

            cmd.Parameters.Add(newParm);

            _db.ExecuteNonQuery(cmd);


            return Common.Public.PublicFunction.NotNullLng(cmd.Parameters["@FInterID"].Value);

        }

        /// <summary>
        /// 获取单据ID
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public static long GetBillID(string tableName)
        {
            return GetBillID(tableName, 1);
        }
       
    }
}
